package com.pengtu.gsj.service.impl.system;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.pengtu.gsj.dao.base.Page;
import com.pengtu.gsj.dao.base.QueryFilter;
import com.pengtu.gsj.dao.base.QueryFilter.MatchType;
import com.pengtu.gsj.dao.system.RoleDao;
import com.pengtu.gsj.entity.app.Role;
import com.pengtu.gsj.service.system.RoleService;

/** 
 * @author zl 
 * @version 创建时间：2017年4月11日 下午3:01:44 
 * 类说明 
 */
@Service
@Transactional
public class RoleServiceImpl implements RoleService {
	
	@Autowired
	private RoleDao roleDao;

	
	@Override
	@Transactional(readOnly = true)
	public Role getRole(String id) {
		return roleDao.get(id);
	}


	@Override
	@Transactional(readOnly = true)
	public Role findRole(String roleName) {
		return roleDao.findUniqueBy("roleName", roleName);
	}


	@Override
	@Transactional(readOnly = true)
	public List<Role> getUseRoles() {
		QueryFilter queryFilter = new QueryFilter();
		queryFilter.addFilter("useFlag", "1", MatchType.EQ);
		return roleDao.find(queryFilter);
	}


	@Override
	public void saveRole(Role entity) {
		roleDao.save(entity);
	}


	@Override
	public void deleteRole(String id) {
		roleDao.delete(id);
	}


	@Override
	@Transactional(readOnly = true)
	public List<String> getRoleCategorys() {
		return roleDao.getRoleCategorys();
	}


	@Override
	@Transactional(readOnly = true)
	public List<String> getRoleIds() {
		return roleDao.getRoleIds();
	}


	@Override
	@Transactional(readOnly = true)
	public List<Role> getRolesBy(String category) {
		return roleDao.findBy("category", category);
	}


	@Override
	@Transactional(readOnly = true)
	public Page<Role> findRoles(Page<Role> page, QueryFilter filters) {
		return roleDao.findPage(page, filters);
	}


	@Override
	@Transactional(readOnly = true)
	public boolean isRoleNameUnique(String newRoleName, String oldRoleName) {
		return roleDao.isPropertyUnique("roleName", newRoleName, oldRoleName);
	}


	@Override
	public List<Role> getAllRole() {
		return roleDao.getAll();
	}



}
